//  https://ac.nowcoder.com/acm/problem/226831

#include<iostream>
using namespace std;

const int N = 1e5 + 10;
int a[N];
int dp[N], len;
int n;

int main()
{
    cin >> n;
    for (int i = 1;i <= n;i++) cin >> a[i];

    for (int i = 1;i <= n;i++)
    {
        if (dp[len] < a[i] || len == 0)
            dp[++len] = a[i];

        int left = 1, right = len;
        while (left < right)
        {
            int mid = (left + right) / 2;
            if (dp[mid] >= a[i]) right = mid;
            else left = mid + 1;
        }
        dp[left] = a[i];
    }
    cout << len << endl;
    return 0;
}